const http = require('http')

//跨域问题，不同的协议，端口，ip下的页面发起http请求会发生跨域问题
http.createServer((req,res)=>{
    if(req.url=='/'){
        var str = ''
        req.on("data",(chunk)=>{
            str+=chunk
        })
        req.on("end",()=>{
            console.log(str)
            var arr = str.split('\r\n')
            var index = arr.indexOf("")
            var index2 = arr.indexOf("",index+1)
            var obj = {"username":arr[index+1],"age":arr[index2+1]}
            console.log(obj)
            //设置允许跨域
            res.setHeader("Access-Control-Allow-Origin",'*')
            res.writeHead(200,{"Content-Type":"text/plain;charset=utf8"})
            res.end("received")
        })
    }
}).listen(8000)
console.log('server is listening 8000')